<template>
  <div id="class-management" class="container">
    <table-filter>
      <school-dept-class-selection
          show-school
          show-dept
          :school-code.sync="apiSetting.data.schoolCode"
          :dept-code.sync="apiSetting.data.deptCode"
      ></school-dept-class-selection>
      <el-button plain type="warning" @click="search">查询</el-button>
    </table-filter>
    <el-row>
      <el-button plain type="primary" @click="addClass">添加班级</el-button>
    </el-row>
    <data-table
        ref="dtb"
        :api-setting="apiSetting"
        :sort-column="sortColumn"
        pagination
    >
      <el-table-column
          fixed
          prop="organizecode"
          label="班级编号"
          width="150"
          sortable
      />
      <el-table-column
          prop="organizename"
          label="班级名称"
          width="180"
          show-overflow-tooltip
      />
      <el-table-column
          prop="school"
          label="学校"
          width="250"
          show-overflow-tooltip
      />
      <el-table-column
          prop="department"
          label="学院"
          width="250"
          show-overflow-tooltip
      />
      <el-table-column prop="description" label="描述" show-overflow-tooltip width="630"/>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="{ row }">
          <el-button @click="edit(row)" type="text" size="small"
          >编辑
          </el-button>
          <el-button
              @click="
              delRow(`/sys/class/deleteClass/${row.organizecode}`, '班级')
            "
              type="text"
              size="small"
              class="danger"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </data-table>
    <ea-class
        ref="eaDialog"
        :show.sync="showEaDialog"
				:dietitle="dialogTit"
        @on-reload="dtb.loadData()"
    ></ea-class>
  </div>
</template>

<script>
import EaClass from "./EaClass";
import dtb from "@/mixins/refs/dtb";
import eaDialog from "@/mixins/refs/eaDialog";
import deleteRow from "@/mixins/dataTable/deleteRow";
import tbSearch from "@/mixins/dataTable/tbSearch";
import SchoolDeptClassSelection from "@/views/component/SchoolDeptClassSelection"



export default {
  name: "index",
  components: {SchoolDeptClassSelection, EaClass},
  mixins: [tbSearch, deleteRow, dtb, eaDialog],
  data() {
    return {
      sortColumn: ["organizecode"],
			dialogTit:'添加班级',//弹窗标题
      apiSetting: {
        method: "post",
        url: "/sys/class/GetClassGrid",
        data: {
          schoolCode: "",
          deptCode: ""
        }
      }
    };
  },
  methods: {
    edit({organizecode}) {
			this.dialogTit="编辑班级"
      this.axios
          .get("/sys/class/getClassDetail", {
            params: {
              classcode: organizecode
            }
          })
          .then(res => {
						this.eaDialog.getDept(res.schoolcode);
            this.showEaDialog = true;
            //多余部分报错注释 this.eaDialog.getDepartment(res.schoolcode);
            this.eaDialog.setEditData({
              singleData: res
            });
          });
    },
    addClass() {
			this.dialogTit="添加班级"
      this.showEaDialog = true;
      if (this.selectedSchool && this.selectedDepartment) {
				this.eaDialog.getDept(this.selectedSchool);
        //多余部分报错注释 this.eaDialog.getDepartment(this.selectedSchool);
        this.$nextTick(() => {
          this.eaDialog.$data.singleData.schoolcode = this.selectedSchool;
          this.eaDialog.$data.singleData.deptcode = this.selectedDepartment;
        });
      }
    }
  }
};
</script>

<style scoped></style>
